#!/bin/sh
#
# triplet.sh: functions for build,host,target triplets.
#
# $Id: triplet.sh.in 586 2008-08-27 03:24:45Z enki $
test $lib_triplet_sh || {

: ${prefix:="@prefix@"}
: ${libdir:="${exec_prefix}/lib"}
: ${shlibdir:="${libdir}/sh"}
: ${tripletdir:="@tripletdir@"}

. $shlibdir/std/array.sh
. $shlibdir/util.sh

# triplet_common <triplet1> <triplet2>
# -------------------------------------------------------------------------
triplet_common()
{
  local t1="$1" t2="$2" p1 p2 part IFS="-"

  set --

  for p1 in $t1
  do
    for p2 in $t2
    do
      if test "$p1" = "$p2"
      then
        set -- "$@" "$p1"
      fi
    done
  done
  echo "$*"
}

# triplet_uncommon <triplet1> <triplet2> [tokens-to-ignore...]
# -------------------------------------------------------------------------
triplet_uncommon()
{
  local t1=`explode "$1" -` t2="$2" p1 IFS="-" ign out=

  shift 2

  for p1 in $t2
  do
    for ign
    do
      if test "$p1" = "$ign"
      then
        continue 2
      fi
    done

    if ! array_isin t1 "$p1"
    then
      out="${out:+$out${IFS:0:1}}$p1"
    fi
  done

  echo "$out"
}

#--- eof ---------------------------------------------------------------------
lib_triplet_sh=:;}
